package com.asj.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.asj.R;
import com.asj.adapter.ProgressAdapter;

import java.util.ArrayList;
import java.util.List;

public class ProgressActivity extends AppCompatActivity {

    //进度条
    private ProgressBar progressBar;
    //展示列表
    private RecyclerView recyclerView;
    //列表的值域
    private List<String> progressSteps;
    //设置列表中每个值的样式
    private ProgressAdapter progressAdapter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.load_page);

        progressBar = findViewById(R.id.progressBar);
        recyclerView = findViewById(R.id.recyclerView);

        // 初始化RecyclerView
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setHasFixedSize(true);

        // 初始化进度步骤列表和适配器
        progressSteps = new ArrayList<>();
        progressAdapter = new ProgressAdapter(progressSteps);
        recyclerView.setAdapter(progressAdapter);

        // 设置初始进度
        progressBar.setMax(40); // 设置进度条的最大值
        progressBar.setProgress(0); // 初始进度为0

        // 模拟进度更新
        /*simulateProgressUpdates();*/
    }

   /* private void simulateProgressUpdates() {
        for (int i = 1; i <= 20; i++) {
            final int progress = i;
            runOnUiThread(() -> {
                progressBar.setProgress(progress);
                progressSteps.add("步骤 " + progress + " 加载中...");
                progressAdapter.notifyItemInserted(progressSteps.size() - 1);
            });
            try {
                Thread.sleep(100); // 模拟耗时操作，减少睡眠时间以加快演示速度
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        // 进度完成后，可以进行额外的操作，比如跳转到另一个页面
        runOnUiThread(() -> {
            // 进度完成，可以在这里进行页面跳转或其他操作
            *//*progressBar.setVisibility(View.GONE);
            recyclerView.setVisibility(View.GONE);*//*
            // Intent intent = new Intent(this, NextActivity.class);
            // startActivity(intent);
        });
    }*/
}